/*
 * @Author: your name
 * @Date: 2021-06-09 18:11:22
 * @LastEditTime: 2021-06-12 12:11:57
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \UDP\SERVER_\dealstr.cpp
 */

#include "dealstr.h"

int DealStr::str_To_Num(char* str)
{
    int length = strlen(str);
    int num = 0;
    for(int i=0; i<length; i++)
    {
        if(str[i]<'0' || str[i]>'9')
        {
            // cout << "length = " << length <<" DealStr::str_To_Num退出，字符串有误:" << str[i] << endl;
            break;
        }
        num = (num + str[i]-'0')*10;
    }
    return num/10;
}

void DealStr::str_To_Array(char* str, int length, int* array)
{
    //遍历str下标
    int str_index = -1;

    // printf("str = %s\n",str);
    // printf("length = %d\n",length);
    // exit(-1);

    //往array填充length个数据
    for(int i=0 ; i<length; i++)
    {
        //保存从字符数组提取出来的字符数字
        char str_num[10];
        //str_num下标
        int str_num_index = 0;
        while(true)
        {
            //初始化-1，在最初+1
            str_index++;

            // cout << "str_length:" << str_index << endl;
            // cout << "str[str_index] = " << *(str+str_index) << endl;

            //数字字符并入str_num
            if(str[str_index] >= '0' && str[str_index] <= '9')
            {
                str_num[str_num_index++] = str[str_index];
            }
            //分割字符结束并入，数字写入array，退出while
            else
            {
                array[i] = this->str_To_Num(str_num);
                break;
            }
        }
    }
}













